import axios from 'axios';
import { fromJS } from 'immutable'

import { INPUT_FOCUS,INPUT_BLUR, CHANGE_LIST,
  CHANGE_PAGE,MOUSE_LEAVE,MOUSE_ENTER } from './actionTypes'

const changeList = (data) => ({
  type: CHANGE_LIST,
  data: fromJS(data),
  total: Math.ceil(data.length / 5)
});


const focusAction = {
  type: INPUT_FOCUS
};

const blurAction = {
  type: INPUT_BLUR
};

const changePage = (page) => ({
  type: CHANGE_PAGE,
  page: page
});

const mouseEnter = (page) => ({
  type: MOUSE_ENTER,
  page: page
});

const mouseLeave = (page) => ({
  type: MOUSE_LEAVE,
  page: page
});

const changeListAction = () => {
  return (dispatch) => {
      axios.get('/api/headerList.json').then((res) => {
        dispatch(changeList(res.data.list));
      }).catch((err) => {
        console.log('出错了....');
      })
  }
};


export {focusAction, blurAction, changeListAction, changePage, mouseEnter, mouseLeave};